package com.daka.tools;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

@SuppressWarnings("unused")
public class CookieUtil {

    public static String getCookieOpenid(HttpServletRequest request) {
        try {
            Cookie[] cookies = request.getCookies();
            if (null != cookies)
                for (Cookie cookie : cookies) {
                    if (cookie.getName().equals("newOpenId")) {
                        return cookie.getValue();
                    }
                }
        } catch (Exception ignored) {
        }
        return null;
    }

    public static String getCookieHeadUrl(HttpServletRequest request) {
        try {
            Cookie[] cookies = request.getCookies();
            if (null != cookies)
                for (Cookie cookie : cookies) {
                    if (cookie.getName().equals("userHeadUrl")) {
                        return cookie.getValue();
                    }
                }
        } catch (Exception ignored) {
        }
        return null;
    }

    public static String getCookieAccess(HttpServletRequest request) {
        try {
            Cookie[] cookies = request.getCookies();
            if (null != cookies)
                for (Cookie cookie : cookies) {
                    if (cookie.getName().equals("accessToken")) {
                        return cookie.getValue();
                    }
                }
        } catch (Exception ignored) {
        }
        return null;
    }

    public static String getSessionId(HttpServletRequest request) {
        try {
            Cookie[] cookies = request.getCookies();
            if (null != cookies)
                for (Cookie cookie : cookies) {
                    if (cookie.getName().equals("sessionId")) {
                        return cookie.getValue();
                    }
                }
        } catch (Exception ignored) {
        }
        return null;
    }

}
